package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class SecondActivity extends BaseActivity implements View.OnClickListener {

    private EditText t1_1;
    private EditText t1_2;

    private Button to_third;
    private int score1 = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_layout);
        initView();
    }

    private void initView() {
        t1_1 = (EditText) findViewById(R.id.t1_1);
        t1_2 = (EditText) findViewById(R.id.t1_2);


        to_third = (Button) findViewById(R.id.to_third);
        to_third.setOnClickListener(this);
    }

    private void submit() {
        // validate
//        Integer n1 = Integer.parseInt(t1_1.getText().toString().trim());
        String s1 = t1_1.getText().toString().trim();
        if (TextUtils.isEmpty(s1)) {
            Toast.makeText(this, "1不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

//        Integer n2 = Integer.parseInt(t1_1.getText().toString().trim());
        String s2 = t1_2.getText().toString().trim();
        if (TextUtils.isEmpty(s2)) {
            Toast.makeText(this, "2不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        // TODO validate success, do something
        if (s1.equals("下划线")) {
            score1 += 10;
        }
        if (s2.equals("美元符号")) {
            score1 += 10;
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.to_third:
                submit();
                //创建意图对象
                Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
//        传递数据
                Bundle bundle = new Bundle();
                bundle.putInt("score_1", score1);
                intent.putExtras(bundle);
                //激活意图
                startActivity(intent);
                break;
        }
    }
}